/// <reference types="vitest" />
import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import env from './src/env-config'
// @ts-ignore bun 无法安装 @types/postcss-px-to-viewport 在 declare.d.ts 中声明
import pxToViewPort from 'postcss-px-to-viewport'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
  ],
  test: {
    environment: 'jsdom',
    coverage: {
      provider: 'istanbul',
    }
  },
  base: env.fileBaseUrl,
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      extensions: 'tsx'
    }
  },
  server: {
    ...env.serverConfig,
    open: 'http://127.0.0.1:7060/#/',
  },
  build: {
    outDir: './mobile'
  },
  css: {
    postcss: {
      plugins: [
        pxToViewPort({
          viewportWidth: 375, // (Number) The width of the viewport.
          viewportHeight: 667, // (Number) The height of the viewport.
          unitPrecision: 5, // (Number) The decimal numbers to allow the REM units to grow to.
          viewportUnit: 'vw', // (String) Expected units.
          selectorBlackList: ['.ignore', '.hairlines'], // (Array) The selectors to ignore and leave as px.
          minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
          mediaQuery: false, // (Boolean) Allow px to be converted in media queries.
        }),
      ]
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import "${path.resolve(__dirname, './src/styles/global-style.less')}";`,
      }
    }
  }
})